{% set template = haproxy_template.squid %}
defaults
	# HTTP based proxy
	mode http

	# Timeouts
	timeout connect            5s
	timeout http-keep-alive    1s
	timeout http-request       15s
	timeout queue              30s
	timeout tarpit             1m
	timeout client             300s
	timeout server             300s
	
	# Logging options
	option httplog
	option dontlognull
	log global

	# Default to round-robin load balancing
	balance uri

	# Ensure NTLM auth works properly
	option http-keep-alive

{% if proxy.defaults is defined %}
	default-server inter {{ proxy.defaults.interval|default(template.interval) }} rise {{ proxy.defaults.rise|default(template.rise) }} fall {{ proxy.defaults.fall|default(template.fall) }}
{% else %}
	default-server inter {{ template.interval }} rise {{ template.rise }} fall {{ template.fall }}
{% endif %}

# Front-End to load balance Squid proxies
frontend fe_{{ name }}
	# Listen on required ports
{% for bind in proxy.frontend.bind %}
	bind {{ bind.ip }}:{{ bind.port }}
{% endfor %}

	# Add "X-Forwarded-For" header
	option forwardfor

	# Use as a monitor
	# monitor-uri {{ proxy.monitor_uri|default("/healthcheck.htm") }}

	# Always use Squid
	use_backend be_{{ name }}

# Squid Back-End
backend be_{{ name }}
	# Ensure NTLM auth works properly
	option prefer-last-server

	# Health check options
	# option httpchk GET http://"${SQUID_FE_IP}":"${SQUID_FE_PORT}"{{ proxy.monitor_uri|default("/healthcheck.htm") }}
	# option log-health-checks
	# http-check expect status 200

	# Squid proxies
{% for server in proxy.backend.server %}
	server {{ server.name }} {{ server.ip }}:{{ server.port }} {% if server.send_proxy|default(false) %}send-proxy {% endif %}check
{% endfor %}
